// 维修设备列表
$(".weixiuzhong").click(function () {
    var num = $(this).attr("data-num");
    mui.confirm("确认开始维修? ", "提示", ["取消", "确认"], function (res) {
        if (res.index == 1) {
            $("#isShow").show();
            $.ajax({
                url: "",
                type: "POST",
                data: {},
                success: function (res) {

                },
            });
        }
    })

});

$(".weixiuwancheng").click(function () {
    var num = $(this).attr("data-num");

    mui.confirm("确认维修完成? ", "提示", ["取消", "确认"], function (res) {
        if (res.index == 1) {
            // loding 显示
            $("#isShow").show();
            $.ajax({
                url: "",
                type: "POST",
                data: {},
                success: function (res) {
                    // loding 隐藏
                    $("#isShow").hide();
                },
            });
        }
    })

});


// 客服分配人员
$("#list .items").click(function () {
    var is = $(this).attr("is");
    if (is == "false") {
        $(this).attr("is", "true");
    } else {
        $(this).attr("is", "false");
    }
});

$("#submitBtn").click(function () {
    // 确定已经选择维修人选
    if (true) {
        mui.confirm("", "确认提交", ["确认", "取消"], function (res) {
            if (res.index == 0) {

                // $("#isShow").show(); //loding显示
                $.ajax({
                    url: "",
                    type: "POST",
                    data: {},
                    success: function (res2) {
                    }
                });
            }
        })
    } else {
        mui.alert("请选择分配的人员", "提示", "确认");
    }
});


// 选择柜子 时租
$("#gridList .items").click(function () {
    $(this).addClass("active").siblings().removeClass("active");
});

$("#submit").click(function () {

    // 选择柜子
    if (true) {
        mui.alert("请选择空闲格口", "提示", "确认");
        return false;
    } else {
        //loding 显示
        $("#isShow").show();
        $.ajax({
            url: "",
            type: "POST",
            data: obj,
            success: function (res) {

            }
        });
    }
});

// 时租  放到页面上

$(function () {
    jisuanTIme();
})

function jisuanTIme() {
    var time = Number($("#startTime").val());
    tuzhi(time);
    setInterval(function () {
        tuzhi(time);
    }, 3000);
}

function tuzhi(time) {
    var xiazeitime = new Date().getTime();
    var danjia = parseInt($("#rentMoney").val());
    var chazhi = parseInt((xiazeitime - time) / 1000 / 60);
    var h = parseInt(chazhi / 60);
    var min = parseInt(chazhi % 60);
    var money = danjia / 60 * chazhi;
    obj.money = money.toFixed(2);
    obj.min = chazhi;
    $("#money").text(money.toFixed(2));
    $("#shiyongH").text(h);
    $("#shiyongMin").text(min);
}

$("#submitBtn").click(function () {
    mui.confirm("确认结束订单?", "提示", ["确认", "取消"], function (res) {
        if (res.index == 0) {
            // $("#isShow").show();
            clearInterval(obj.jishiqi);
            $.ajax({
                url: "",
                type: "POST",
                data: {},
                success: function (res2) {

                },
            });
        }
    });
});


//  workers one 设备维修

$("#replace").click(function () {
    $("#cabinetTwo").show();
});


/**
 * 获取设备
 *        动态添加设备
 */
$("#searchDeviceBtn").click(function () {
    var selectDeviceNumber = $("#selectDeviceNumber").val();
    obj.deviceNo = selectDeviceNumber;
    console.log(selectDeviceNumber)
    if (selectDeviceNumber == null || selectDeviceNumber == undefined || selectDeviceNumber == "") {
        mui.alert("设备号不能为空", "提示", "确认");
        return false;
    } else {
        $("#isShow").show();
        $.ajax({
            url: "",
            type: "POST",
            data: {},
            success: function (res) {
                $("#isShow").hide();
                // 动态添加 设备时候 调用 load 函数
            },
            error: function (err) {
                $("#isShow").hide();
                mui.alert("获取设备失败,请刷新重试。", "错误提示", "确认");
            }
        });
    }
});


/**
 * 设备报修提交
 */
$("#tijiao").click(function () {
    if (obj.type == null || obj.type == undefined) {
        mui.alert("请选择故障的处理方式", "提示", "确认");
    } else if (obj.type == 1 && obj.type) {
        if (obj.deviceNo == null || obj.deviceNo == undefined || obj.deviceNo == "") {
            mui.alert("请输入你要更换的设备号。", "提示", "确认");
            return false;
        } else {
            if (obj.cabinetMouth == null || obj.cabinetMouth == undefined) {
                mui.alert("请选择要更换至的格口", "提示", "确认");
                return false;
            }
        }

    } else if (obj.malfunction == null || obj.malfunction == undefined) {
        mui.alert("请选择故障类型", "提示", "确认");
        return false;
    } else {
        console.log(obj);
        mui.alert("感谢您的反馈, 我们会尽快维修。", "提交完成", "确认");
        return false;
        var detail = $("#malfunctionDetail").val();
        var data = obj;
        data.detail = detail;
        $.ajax({
            url: "",
            type: "POST",
            data: data,
            success: function (res) {
                mui.alert("感谢您的反馈, 我们会尽快维修。", "提交完成", "确认");
            }
        });
    }

});

